import 'package:flutter/material.dart';
import 'package:flutterdemo/common/calc.dart';
import 'package:flutterdemo/components/button.dart';
import 'package:flutterdemo/components/my_appbar.dart';

class Address extends StatefulWidget {
  Address({Key? key}) : super(key: key);

  @override
  _AddressState createState() => _AddressState();
}

class _AddressState extends State<Address> {
  // 底部操作栏
  Widget _addBottom() {
    return Container(
      padding: EdgeInsets.only(top: Calc.width(20), bottom: Calc.width(20)),
      decoration: BoxDecoration(
      color: Colors.white,
        border: Border(top: BorderSide(color: Color.fromRGBO(233, 233, 233, 1),width: 1),)
      ),
      width: double.infinity,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          MyButton(
            "新增收货地址",
            onPressed: () {},
            width: Calc.width(600),
          )
        ],
      ),
    );
  }

  // 地址内容
  Widget _addItem() {
    return Ink(
      padding: EdgeInsets.all(Calc.width(20)),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(Calc.width(20)),
        color: Colors.white,
      ),
      child: Column(
        children: [
          Row(
            children: [
              Container(
                height: Calc.width(80),
                width: Calc.width(80),
                decoration: BoxDecoration(
                  color: Theme.of(context).accentColor,
                  borderRadius: BorderRadius.circular(Calc.width(40)),
                ),
                child: Center(child: Text("马",style: TextStyle(color: Colors.white,fontSize: Calc.width(40)),),),
              ),
              SizedBox(width: Calc.width(20),),
              Expanded(
                flex: 1,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.end,
                      children: [
                        Text(
                          "马云",
                          style: TextStyle(fontSize: 18),
                        ),
                        SizedBox(
                          width: Calc.width(10),
                        ),
                        Text("18085080293",
                            style: TextStyle(
                                fontSize: 14, height: 1.5, color: Colors.grey)),
                      ],
                    ),
                    Text("贵州省 贵阳市 南明区 延安南路区"),
                  ],
                ),
              ),
              Icon(Icons.edit_location,color: Theme.of(context).accentColor,),
            ],
          ),
          SizedBox(height: Calc.width(20),),
          Divider(),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Row(
                children: [
                  Radio(
                    materialTapTargetSize:MaterialTapTargetSize.shrinkWrap,
                    value: 1,
                    groupValue:0,
                    onChanged: (e){
                      print(e);
                    },
                  ),
                  Text("设为默认地址")
                ],
              ),
              Text("删除",style: TextStyle(color: Colors.grey),)
            ],
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    Calc.init(context);
    return Scaffold(
      backgroundColor: Color.fromRGBO(233, 233, 233, 1),
      appBar: MyAppBar().getAppBar("收货地址"),
      body: Column(
        children: [
          Expanded(
            child: ListView(
              padding: EdgeInsets.all(Calc.width(20)),
              physics: BouncingScrollPhysics(),
              children: [
                _addItem(),
                SizedBox(height: Calc.height(20),),
                _addItem(),
                SizedBox(height: Calc.height(20),),
                _addItem(),
                SizedBox(height: Calc.height(20),),
                _addItem(),
                SizedBox(height: Calc.height(20),),
                _addItem(),
              ],
            ),
            flex: 1,
          ),
          _addBottom()
        ],
      ),
    );
  }
}
